<template>
  <a-modal :open="open" width="640px" title="修改预约" centered ok-text="保存" @ok="onOk" @cancel="onCancel">
    <a-form :model="formState" class="form-style-flex">
      <a-form-item label="原预约日期" class="w-1/2">
        <a-date-picker v-model:value="formState.oldyyrq" disabled class="w-full" value-format="YYYY-MM-DD" placeholder="请选择" />
      </a-form-item>
      <a-form-item label="原预约时间" class="w-1/2">
        <a-time-picker v-model:value="formState.oldyytime" disabled value-format="HH:mm" class="w-full" />
      </a-form-item>
      <a-form-item label="现预约日期" class="w-1/2">
        <a-date-picker v-model:value="formState.yyrq" class="w-full" value-format="YYYY-MM-DD" placeholder="请选择" />
      </a-form-item>
      <a-form-item label="现预约时间" class="w-1/2">
        <a-time-picker v-model:value="formState.yytime" value-format="HH:mm" class="w-full" />
      </a-form-item>
    </a-form>
  </a-modal>
</template>
<script setup>
import { ref, watch } from 'vue'
import { message } from 'ant-design-vue'
import { post } from '@/utils/request'

const emit = defineEmits(['update:open', 'success'])
const props = defineProps({
  open: Boolean,
  rowData: {
    type: Object,
    default: () => ({})
  }
})
const formState = ref({
  empName: ''
})

const onCancel = () => {
  emit('update:open', false)
}
const onOk = async () => {
  const { code, msg } = await post('/outp/mzdj/upAppointmentDate', {
    ...formState.value
  })
  if (code === 0) {
    message.success(msg)
    emit('success')
    onCancel()
  } else {
    message.error(msg)
  }
}

watch(
  () => props.open,
  (val) => {
    if (val) {
      formState.value = {
        oldyytime: props.rowData?.yysj,
        oldyyrq: props.rowData?.yyrq,
        yylsh: props.rowData?.yylsh
      }
    }
  }
)
</script>
